#include "stdafx.h"
#include <assert.h>
#include <glut.h>

#include "InputSystem.h"
#include "KeyboardHandler.h"
#include "MouseHandler.h"
#include "Utility.h"

CInputSystem::CInputSystem( ) :
	m_KeyboardHandler( NULL ),
	m_MouseHandler( NULL )
{
	m_KeyboardHandler = new CKeyboardHandler( );
	m_MouseHandler = new CMouseHandler( );
}

CInputSystem::~CInputSystem( )
{
	delete m_KeyboardHandler;
	delete m_MouseHandler;
}

bool CInputSystem::Update( )
{
	bool theSuccess = false;

	assert( m_KeyboardHandler );
	theSuccess = m_KeyboardHandler->Update( );

	assert( m_MouseHandler );
	theSuccess |= m_MouseHandler->Update( );

	m_KeyboardHandler->Clear( );
	m_MouseHandler->Clear( );

	return theSuccess;
}

bool CInputSystem::HandleKeyboard( const unsigned char inKey, const int inPosX, const int inPosY )
{
	assert( m_KeyboardHandler );
	return m_KeyboardHandler->HandleKeyboard( inKey, inPosX, inPosY );
}

bool CInputSystem::HandleSpecialKey( const int inKey, const int inPosX, const int inPosY )
{
	assert( m_KeyboardHandler );
	return m_KeyboardHandler->HandleSpecialKey( inKey, inPosX, inPosY );
}

bool CInputSystem::HandleMouse( const int inButton, const int inState, const int inPosX, const int inPosY )
{
	assert( m_MouseHandler );
	return m_MouseHandler->HandleMouse( inButton, inState, inPosX, inPosY );
}

bool CInputSystem::HandleMotion( const int inPosX, const int inPosY )
{
	//printf( "Motion : Pos X = %d Pos Y = %d\n", inPosX, inPosY );
	GLdouble wx, wy, wz;
	return CUtility::UnProjectScreenPosition( inPosX, inPosY, wx, wy, wz );
}
